package com.coldworks.coldjoke.ui;

import com.coldworks.coldjoke.R;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public final class PopWindowUtils {

	public interface OnItemSelected {
		void onClick(int itemID);
	}

	public static PopupWindow MenuLoginView(Context context,
			final OnItemSelected alertDo) {
		LinearLayout vMenu;
		vMenu = (LinearLayout) LayoutInflater.from(context).inflate(
				R.layout.menu_login, null);
		final PopupWindow vPopupWindow = new PopupWindow(vMenu,
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

		vMenu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				vPopupWindow.dismiss();
			}
		});

		vMenu.findViewById(R.id.button_login).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_login);

					}
				});

		vMenu.findViewById(R.id.button_register).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_register);

					}
				});
		vMenu.findViewById(R.id.button_cancle).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_cancle);

					}
				});

		vPopupWindow.update();
		vPopupWindow.setFocusable(true);
		vPopupWindow.setAnimationStyle(android.R.style.Animation_InputMethod);
		ColorDrawable cd = new ColorDrawable(context.getResources().getColor(
				R.color.transparent));
		vPopupWindow.setBackgroundDrawable(cd);
		return vPopupWindow;
	}

	public static PopupWindow MenuReportView(Context context,
			final OnItemSelected alertDo) {
		LinearLayout vMenu;
		vMenu = (LinearLayout) LayoutInflater.from(context).inflate(
				R.layout.menu_report, null);
		final PopupWindow vPopupWindow = new PopupWindow(vMenu,
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

		vMenu.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				vPopupWindow.dismiss();
			}
		});

		vMenu.findViewById(R.id.button_report_1).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_report_1);

					}
				});

		vMenu.findViewById(R.id.button_report_2).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_report_2);

					}
				});
		vMenu.findViewById(R.id.button_report_3).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_report_3);

					}
				});
		vMenu.findViewById(R.id.button_report_4).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_report_4);

					}
				});
		vMenu.findViewById(R.id.button_cancle).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						vPopupWindow.dismiss();
						alertDo.onClick(R.id.button_cancle);

					}
				});

		vPopupWindow.update();
		vPopupWindow.setFocusable(true);
		vPopupWindow.setAnimationStyle(android.R.style.Animation_InputMethod);
		ColorDrawable cd = new ColorDrawable(context.getResources().getColor(
				R.color.transparent));
		vPopupWindow.setBackgroundDrawable(cd);
		return vPopupWindow;
	}
}
